package com.yonglian.management.service.impl;

import com.yonglian.management.domain.ProjectType;
import com.yonglian.management.repository.ProjectTypeRepository;
import com.yonglian.management.service.ProjectTypeService;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service Implementation for managing {@link com.yonglian.management.domain.ProjectType}.
 */
@Service
@Transactional
public class ProjectTypeServiceImpl implements ProjectTypeService {

    private final Logger log = LoggerFactory.getLogger(ProjectTypeServiceImpl.class);

    private final ProjectTypeRepository projectTypeRepository;

    public ProjectTypeServiceImpl(ProjectTypeRepository projectTypeRepository) {
        this.projectTypeRepository = projectTypeRepository;
    }

    @Override
    public ProjectType save(ProjectType projectType) {
        log.debug("Request to save ProjectType : {}", projectType);
        return projectTypeRepository.save(projectType);
    }

    @Override
    public ProjectType update(ProjectType projectType) {
        log.debug("Request to update ProjectType : {}", projectType);
        return projectTypeRepository.save(projectType);
    }

    @Override
    public Optional<ProjectType> partialUpdate(ProjectType projectType) {
        log.debug("Request to partially update ProjectType : {}", projectType);

        return projectTypeRepository
            .findById(projectType.getId())
            .map(existingProjectType -> {
                if (projectType.getTypeName() != null) {
                    existingProjectType.setTypeName(projectType.getTypeName());
                }
                if (projectType.getRemark() != null) {
                    existingProjectType.setRemark(projectType.getRemark());
                }

                return existingProjectType;
            })
            .map(projectTypeRepository::save);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<ProjectType> findAll(Pageable pageable) {
        log.debug("Request to get all ProjectTypes");
        return projectTypeRepository.findAll(pageable);
    }

    @Override
    @Transactional(readOnly = true)
    public Optional<ProjectType> findOne(Long id) {
        log.debug("Request to get ProjectType : {}", id);
        return projectTypeRepository.findById(id);
    }

    @Override
    public void delete(Long id) {
        log.debug("Request to delete ProjectType : {}", id);
        projectTypeRepository.deleteById(id);
    }
}
